using System;
using Firestarter.Test.Base;
using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.Base.Exceptions;
using Habanero.BO;
using NUnit.Framework;

namespace FireStarterModeller.Test.BO
{
    [TestFixture]
    public class TestUIViewMustHaveUIGridAndUIForm
    {
        [SetUp]
        public void SetupTest()
        {
            //Runs every time that any testmethod is executed
            TestUtilsDomain.SetupTest();
            BORegistry.DataAccessor = new DataAccessorInMemory();
        }

        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            //Code that is executed before any test is run in this class. If multiple tests
            // are executed then it will still only be called once.
            TestUtilsDomain.SetupFixture();
        }

        [TearDown]
        public void TearDownTest()
        {
            //runs every time any testmethod is complete
        }

        #region UIViewMustHaveUIGridOrUIForm

        [Test]
        public void Test_CreateUIViewMustHaveUIGridAndUIForm()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            UIView uiView = dmClass.UIViews.CreateBusinessObject();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            IBusinessObjectRule rule = new UIViewMustHaveUIGridOrUIForm();
            //---------------Test Result -----------------------
            Assert.IsNotNull(rule);
            Assert.AreEqual("UIViewMustHaveUIGridOrUIForm", rule.Name);
            Assert.AreEqual(ErrorLevel.Warning, rule.ErrorLevel);
        }

//        [Test]
//        public void Test_CreateUIViewMustHaveUIGridAndUIForm_WhenUIViewNull_ShouldRaiseError()
//        {
//            //---------------Set up test pack-------------------
//            //---------------Assert Precondition----------------
//            //---------------Execute Test ----------------------
//            try
//            {
//                new UIViewMustHaveUIGridOrUIForm(null);
//                Assert.Fail("expected ArgumentNullException");
//            }
//                //---------------Test Result -----------------------
//            catch (ArgumentNullException ex)
//            {
//                StringAssert.Contains("Value cannot be null", ex.Message);
//                StringAssert.Contains("uiView", ex.ParamName);
//            }
//        }

//        [Test]
//        public void Test_CreateUIViewMustHaveUIGridAndUIForm_WhenClassNull_ShouldRaiseError()
//        {
//            //---------------Set up test pack-------------------
//            UIView uiView = new UIView();
//            //---------------Assert Precondition----------------
//            Assert.IsNull(uiView.Class);
//            //---------------Execute Test ----------------------
//            try
//            {
//                new UIViewMustHaveUIGridOrUIForm();
//                Assert.Fail("expected HabaneroArgumentException");
//            }
//                //---------------Test Result -----------------------
//            catch (HabaneroArgumentException ex)
//            {
//                StringAssert.Contains("The uiView.Class cannot be null for the uiView", ex.Message);
//                StringAssert.Contains("uiView", ex.ParameterName);
//            }
//        }

        [Test]
        public void Test_WhenFormIsCreatedButNotGrid_ShouldPass()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            UIView uiView = dmClass.UIViews.CreateBusinessObject();
            uiView.UIFormInfo = new UIFormInfo();
            IBusinessObjectRule rule = new UIViewMustHaveUIGridOrUIForm();
            //---------------Assert Precondition----------------
            Assert.IsNull(uiView.UIGridInfo);
            Assert.IsNotNull(uiView.UIFormInfo);
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(uiView);
            //---------------Test Result -----------------------
            Assert.IsTrue( isValid);
        }

        [Test]
        public void Test_WhenGridIsCreatedButNotForm_ShouldPass()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            UIView uiView = dmClass.UIViews.CreateBusinessObject();
            uiView.UIGridInfo = new UIGridInfo();
            IBusinessObjectRule rule = new UIViewMustHaveUIGridOrUIForm();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(uiView.UIGridInfo);
            Assert.IsNull(uiView.UIFormInfo);
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(uiView);
            //---------------Test Result -----------------------
            Assert.IsTrue(isValid);
        }

        [Test]
        public void Test_WhenGridAndViewIsCreated_ShouldPass()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedDefaultDMClass();
            UIView uiView = dmClass.UIViews.CreateBusinessObject();
            uiView.UIGridInfo = new UIGridInfo();
            uiView.UIFormInfo = new UIFormInfo();
            IBusinessObjectRule rule = new UIViewMustHaveUIGridOrUIForm();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(uiView.UIGridInfo);
            Assert.IsNotNull(uiView.UIFormInfo);
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(uiView);
            //---------------Test Result -----------------------
            Assert.IsTrue(isValid);
        }

        #endregion
    }
}